<!DOCTYPE html>
<html>
  <head>
    <title>WebSocket测试页面</title>
    <meta charset="UTF-8" />
    <object
      id="ctrl"
      classid="clsid:7356CC90-5909-4f44-A07E-329D0BD3FF81"
      VIEWASTEXT
      width="0"
      height="0"
    ></object>
    <!--需要修改所加载ActiveX控件的classid-->
    <script src="te99_websocket.js"></script>
    <script src="te99_test.js"></script>
    <script type="text/javascript">
      var ctrl = null;
      var websock = true;
      var pid;
      var userpin;
      var keyid;
      var keybuff;
      var md5input;
      var usertype;
      var et99index;
      var databuf, roffset, rlen, woffset, wlen;

      function OnLoad() {
        try {
          ctrl = new AtlCtrlForET99("{7356CC90-5909-4f44-A07E-329D0BD3FF81}");
        } catch (e) {
          ctrl = null;
          websock = false;
        }
      }

      //查找et99
      function ET99_FindToken() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          pid = document.getElementById("CurrentPid").value;
          rtn = ctrl.ET99_FindToken(pid);
          alert(rtn);
        } else {
          pid = document.getElementById("CurrentPid").value;
          ctrl.ET99_FindToken(function (result, response) {
            if (!result) {
              alert("ET99_FindToken error. " + response);
            } else {
              rtn = response;
              alert(rtn);
            }
          });
        }
      }
      //打开et99
      function ET99_OpenToken() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          pid = document.getElementById("CurrentPid").value;
          et99index = document.getElementById("ET99Index").value;
          rtn = ctrl.ET99_OpenToken(pid, et99index);
          if (0 == rtn) {
            // alert("打开锁成功");
            document.getElementById("ET99_OpenToken2").textContent =
              "打开锁成功";
          } else {
            // alert("打开指定的锁失败");
            document.getElementById("ET99_OpenToken2").textContent =
              "打开指定的锁失败";
          }
        } else {
          pid = document.getElementById("CurrentPid").value;
          et99index = document.getElementById("ET99Index").value;
          ctrl.ET99_OpenToken(function (result, response) {
            if (!result) {
              alert("ET99_OpenToken error. " + response);
            } else {
              rtn = response;
              if (0 == rtn) {
                // alert("打开锁成功");
                document.getElementById("ET99_OpenToken2").textContent =
                  "打开锁成功";
              } else {
                // alert("打开指定的锁失败");
                document.getElementById("ET99_OpenToken2").textContent =
                  "打开指定的锁失败";
              }
            }
          });
        }
      }

      //获取序列号,锁必须为open状态才可以获取到序列号
      function ET99_GetSN() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_GetSN();
          document.getElementById("snresult").value = rtn;
        } else {
          ctrl.ET99_GetSN(function (result, response) {
            if (!result) {
              alert("ET99_GetSN error. " + response);
            } else {
              rtn = response;
              document.getElementById("snresult").value = rtn;
            }
          });
        }
      }
      //验证PIN码
      function ET99_Verify() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          userpin = document.getElementById("CurrentPin").value;
          //获取要验证的用户类型
          oListbox = document.getElementById("selectUser");
          var indx = oListbox.selectedIndex;
          if (indx == 0) usertype = 0;
          if (indx == 1) usertype = 1;
          //参数中的0表示验证普通用户pin码，1表示验证超级用户pin码
          rtn = ctrl.ET99_Verify(usertype, userpin);
          if (0 == rtn) {
            // alert("验证PIN码成功");
            document.getElementById("ET99_Verify2").textContent =
              "验证PIN码成功" + usertype;
          } else {
            // alert("验证PIN码失败");
            document.getElementById("ET99_Verify2").textContent =
              "验证PIN码失败" + usertype;
          }
        } else {
          userpin = document.getElementById("CurrentPin").value;
          //获取要验证的用户类型
          oListbox = document.getElementById("selectUser");
          var indx = oListbox.selectedIndex;
          if (indx == 0) usertype = 0;
          if (indx == 1) usertype = 1;
          ctrl.ET99_Verify(function (result, response) {
            if (!result) {
              alert("ET99_Verify error. " + response);
            } else {
              rtn = response;
              if (0 == rtn) {
                // alert("验证PIN码成功");
                document.getElementById("ET99_Verify2").textContent =
                  "验证PIN码成功" + usertype;
              } else {
                // alert("验证PIN码失败");
                document.getElementById("ET99_Verify2").textContent =
                  "验证PIN码失败" + usertype;
              }
            }
          });
        }
      }
      //生成随机数，必须为验证userpin的状态下才能使用
      function ET99_GenRandom() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_GenRandom();
          document.getElementById("randomresult").value = rtn;
        } else {
          ctrl.ET99_GenRandom(function (result, response) {
            // alert(response);
            if (!result) {
              //   alert("ET99_GenRandom error. " + response);
            } else {
              rtn = response;
              document.getElementById("randomresult").value = rtn;
            }
          });
        }
      }
      function ET99_Read() {
        roffset = document.getElementById("readset").value;
        rlen = document.getElementById("readlen").value;
        databuf = "1";
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_Read(roffset, rlen);
          document.getElementById("readdata").value = rtn;
        } else {
          ctrl.ET99_Read(function (result, response) {
            if (!result) {
              alert("ET99_Read error. " + response);
            } else {
              rtn = response;
              document.getElementById("readdata").value = response;
            }
          });
        }
      }

      function ET99_Write() {
        woffset = document.getElementById("writeset").value;
        wlen = document.getElementById("writelen").value;
        databuf = document.getElementById("writedata").value;

        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_Write(woffset, wlen, databuf);
          alert(rtn);
        } else {
          ctrl.ET99_Write(function (result, response) {
            if (!result) {
              alert("ET99_Write error. " + response);
            } else {
              rtn = response;
              //document.getElementById("writedata").value=rtn;

              if (0 == rtn) {
                alert("写入数据成功");
              } else {
                alert("写入失败");
              }
            }
          });
        }
      }
      //设置用于计算MD5的密码索引及密码
      function ET99_SetKey() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          keyid = document.getElementById("keyindex").value;
          keybuff = document.getElementById("keytext").value;
          rtn = ctrl.ET99_SetKey(keyid, keybuff);
          alert(rtn);
        } else {
          keyid = document.getElementById("keyindex").value;
          keybuff = document.getElementById("keytext").value;
          ctrl.ET99_SetKey(function (result, response) {
            if (!result) {
              // alert("ET99_SetKey error. " + response);
              document.getElementById("ET99_SetKey2").textContent =
                "ET99_SetKey error. " + response;
            } else {
              rtn = response;
              // alert(rtn);
              document.getElementById("ET99_SetKey2").textContent = rtn;
            }
          });
        }
      }
      //通过et99的硬件计算MD5值
      function ET99_HMAC_MD5() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          keyid = document.getElementById("keyindex").value;
          md5input = document.getElementById("md5plain").value;
          rtn = ctrl.ET99_HMAC_MD5(keyid, 6, md5input);
          document.getElementById("md5result").value = rtn;
        } else {
          keyid = document.getElementById("keyindex").value;
          md5input = document.getElementById("md5plain").value;
          ctrl.ET99_HMAC_MD5(function (result, response) {
            if (!result) {
              alert("ET99_HMAC_MD5 error. " + response);
            } else {
              rtn = response;
              document.getElementById("md5result").value = rtn;
            }
          });
        }
      }
      //关闭et99
      function ET99_CloseToken() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_CloseToken();
          if (0 == rtn) {
            // alert("关闭锁成功");
            document.getElementById("ET99_CloseToken2").textContent =
              "关闭锁成功";
          } else {
            // alert("关闭锁失败");
            document.getElementById("ET99_CloseToken2").textContent =
              "关闭锁失败";
          }
        } else {
          ctrl.ET99_CloseToken(function (result, response) {
            if (!result) {
              alert("ET99_CloseToken error. " + response);
            } else {
              rtn = response;
              if (rtn == 0) {
                // alert("关闭锁成功");
                document.getElementById("ET99_CloseToken2").textContent =
                  "关闭锁成功";
              } else {
                // alert("关闭锁失败");
                document.getElementById("ET99_CloseToken2").textContent =
                  "关闭锁失败";
              }
            }
          });
        }
      }
      //获取本机mac地址
      function GetMacAddress() {
        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.GetMacAddress();
          document.getElementById("macresult").value = rtn;
        } else {
          ctrl.GetMacAddress(function (result, response) {
            // alert(response);
            if (!result) {
              alert("GetMacAddress error. " + response);
            } else {
              rtn = response;
              document.getElementById("macresult").value = rtn;
            }
          });
        }
      }

      function ET99_ChangeUserPIN() {
        oldpin = document.getElementById("oldpin").value;
        newpin = document.getElementById("newpin").value;

        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_ChangeUserPIN(oldpin, newpin);
        } else {
          ctrl.ET99_ChangeUserPIN(function (result, response) {
            if (!result) {
              alert("chagneuserpin error" + response);
            } else {
              rtn = response;
              if (rtn == 0) {
                alert("chagneuserpin ok");
              } else {
                alert("changeuserpin fail");
              }
            }
          });
        }
      }
      function ET99_GenPID() {
        pidseed = document.getElementById("seed").value;

        if (!websock) {
          ctrl = document.getElementById("ctrl");
          rtn = ctrl.ET99_GenPID(pidseed);
        } else {
          ctrl.ET99_GenPID(function (result, response) {
            if (!result) {
              alert("genpid error" + response);
            } else {
              rtn = response;
              document.getElementById("newpid").value = rtn;
            }
          });
        }
      }
    </script>
  </head>

  <body LANGUAGE="javascript" onload="OnLoad()">
    <h1 align="center">ET99多浏览器插件测试页面</h1>
    <hr color="#006400" size="5" />
    本机MAC地址:<input
      id="macresult"
      type="text"
      value=""
      style="width: 240px"
    />
    <input
      id="GetMacAddress"
      onclick="GetMacAddress()"
      type="button"
      value="本机网卡地址"
      name="GetMacAddress"
      style="width: 100px"
    />
    <br />
    PID:<input
      id="CurrentPid"
      type="text"
      value="1C44DFCF"
      style="width: 90px"
    />
    <input
      id="ET99_FindToken"
      onclick="ET99_FindToken()"
      type="button"
      value="查找U-KEY"
      name="ET99_FindToken"
      style="width: 90px"
    />
    (第<input
      id="ET99Index"
      type="text"
      value="1"
      style="width: 20px"
    />把U-KEY)

    <input
      id="ET99_CloseToken"
      onclick="ET99_CloseToken()"
      type="button"
      value="关闭"
      name="ET99_CloseToken"
      style="width: 60px"
    />
    <span style="color: tomato" id="ET99_CloseToken2">?</span>

    <input
      id="ET99_OpenToken"
      onclick="ET99_OpenToken()"
      type="button"
      value="打开"
      name="ET99_OpenToken"
      style="width: 60px"
    />
    <span style="color: tomato" id="ET99_OpenToken2">?</span>

    <br />
    SN:<input id="snresult" type="text" value="" style="width: 140px" />
    <input
      id="ET99_GetSN"
      onclick="ET99_GetSN()"
      type="button"
      value="USB-KEY序列号"
      name="ET99_GetSN"
      style="width: 140px"
    /><br />

    PIN:<input
      id="CurrentPin"
      type="text"
      value="FFFFFFFFFFFFFFFF"
      size="20"
      style="width: 120px"
    />
    <select name="selectUser" id="selectUser">
      <option value="1">普通用户</option>
      <option value="2">超级用户</option>
    </select>
    <input
      id="ET99_Verify"
      onclick="ET99_Verify()"
      type="button"
      value="密码验证/登录"
      name="ET99_Verify"
      style="width: 140px"
    />
    <span style="color: tomato" id="ET99_Verify2">?</span>
    <br />
    得到的随机数(须登录用户):<input
      id="randomresult"
      type="text"
      value=""
      style="width: 240px"
    />
    <input
      id="ET99_GenRandom"
      onclick="ET99_GenRandom()"
      type="button"
      value="生成随机数"
      name="ET99_GenRandom"
      style="width: 140px"
    />
    <br />
    修改userpin即普通用户密码(新旧密码都是16位):
    <input id="oldpin" type="text" value="" />再次:<input
      id="newpin"
      type="text"
      value=""
    />
    <input
      id="changeuserpin"
      type="button"
      onclick="ET99_ChangeUserPIN()"
      value="修改普通用户密码"
      style="width: 140px"
    /><br />
    <span style="color: tomato"
      >-普通用户PIN可自行修改,超级用户PIN使用专用工具生成-</span
    >

    <br />
    产生新的PID(先要验证sopin即超级用户)-输入种子码(最长50位):
    <input id="seed" type="text" value="" style="width: 300px" />
    <input
      id="genid"
      type="button"
      onclick="ET99_GenPID()"
      value="生成新PID"
      style="width: 90px"
    />
    新的PID:<input id="newpid" type="text" value="" /><br /><br />
    向USB-KEY数据区进行操作-根据用户权限操作:<br />
    写入的开始位置:<input id="writeset" type="text" value="0" size="3" /><br />
    写入的长度0~60:<input id="writelen" type="text" value="32" size="3" /><br />
    写入的数据:<input id="writedata" type="text" size="60" value="123456abc" />
    <input
      id="ET99_Write"
      onclick="ET99_Write()"
      type="button"
      value="写入数据"
      name="ET99_Write"
      style="width: 140px"
    />
    <br />
    读取的开始位置:<input id="readset" type="text" value="0" size="3" /><br />
    读取的长度0~60:<input id="readlen" type="text" value="60" size="3" /><br />
    读出的数据:<input id="readdata" type="text" size="60" value="" />
    <input
      id="ET99_Read"
      onclick="ET99_Read()"
      type="button"
      value="读出数据"
      name="ET99_Read"
      style="width: 140px"
    /><br /><br />
    向USB-KEY密钥区<span style="color: tomato">写入</span
    >-本区数据只写-不能被读取-仅USB-KEY内部计算密文用:<br />
    密钥索引1~8:<input
      id="keyindex"
      type="text"
      size="4"
      value="1"
      style="width: 40px"
    />
    设置密钥:<input
      id="keytext"
      type="text"
      value="123456"
      style="width: 240px"
    />
    <input
      id="ET99_SetKey"
      onclick="ET99_SetKey()"
      type="button"
      value="向指定索引区写密钥"
      name="ET99_SetKey"
      style="width: 140px"
    />-根据用户权限操作-
    <span style="color: tomato" id="ET99_SetKey2">?</span>

    <br /><br />
    (MD5原文,MD5密文)-这两个参数可公开一起传送给后端服务器对比-<span
      style="color: tomato"
      >使用上面输入框的密钥索引进行生成</span
    ><br />
    MD5原文(可以用随机数):<input
      id="md5plain"
      type="text"
      value="123456"
      style="width: 240px"
    />
    <input
      id="ET99_HMAC_MD5"
      onclick="ET99_HMAC_MD5()"
      type="button"
      value="生成HMAC_MD5密文"
      name="ET99_HMAC_MD5"
      style="width: 170px"
    />
    MD5结果:<input id="md5result" type="text" value="" style="width: 300px" />

    <br /><br />
  </body>
</html>
